Sample Code
Sample Pascal programs
Regular Pascal programs
   
simplest.p (Program stub)
   
simplest2.p (Hello world)
   
if.p (Demonstrate if)
   
add.p (Demonstrate arrays and procedures)
   
subscripts.p (Demonstrate differently
subscripted arrays )
   
case.p (Demonstrate repeat loop and case statement)
   
pointer.p (Pointers to non-record types)
Medium Pascal programs
   
array.p (Demonstrate arrays)
   
array2.p (Arrays with character indexes)
   
list.p (Demonstrate linked list - pointers, records)
       
list.data (Data that could be used with linked
list)
   
fact.p (Function call with more complex returning)
Hard Pascal programs
   
set.p (Demonstrate the set datatype)
   
nestedprocs.p (Nested procedures)
   
symboltabletest.p (Pascal simulated to test ST)
   
list2.p (Linked list - with function call and
dispose)
Pascal programs with errors
   
simpleerror.p (Program stub with lexical error)
   
symboltableerror.p (Lots of errors to test ST)
   
harderror.p (Harder error with undefined pointer)
   
funcerror.p (Error using function call incorrectly)
   
arrayerror.p (Arrays with string indexes)
   
errors.p (Undefined vars and type checking errors)
tokenconsts.h  
lexdata.txt   Random Pascal tokens
C++ code examples
   
Using a "union" - variant record
   
UML  
Inheritance program  
output  
- shows C++ needed for building the symbol table
   
More code from CSS 343
   
Example of using STL map as hash table  
- provided by Ken Rice
Simple (f)lex example
   
makefile   Enter "make" ...
creates the executable file a.out
   
lex file: ll   Name it whatever you want
   
lex.yy.c   lex creates the function
yylex() that the parser will call (ugly C code)
   
main.cpp   The main that calls yylex()
   
ll.txt   Sample data file ...
to execute, enter:   a.out < ll.txt
   
Output   from the execution
One of the
lex links
I provided (click on "More Lex" and then "Reserved") talks about it
being more efficient to detect reserved words and identifiers simultaneously.
Other makefile examples
Remember makefiles must be named "makefile" or "Makefile" .
If you compile without linking, under unix you get a   ".o"   file,
an object file. This is similar to a   ".obj"   file in windows.
   
makefile example 1
   
makefile example 2
   
makefile example 3