Package jelan.elan.parser

This package is responsible for parsing the language Elan.

See:
          Description

Interface Summary
Parser  
 

Class Summary
AssignmentParser Parse an assignment statement, which is looks like
ElanParser Illustrates the java.io.StreamTokenizer class and how it can be used to parse tokens for a toy example programming language (elan).
ExpressionParser This is a recursive descent parser for parsing expressions using the standard grammar for expressions (follows).
IdentifierParser  
InstructionNames  
InstructionParser Instruction Parser - calls appropriate Parser for each Instruction
PrintParser  
RepeatParser Parse a REPEAT Statement, which looks like REPEAT numOrVar [ instructionlist ]
StrictInstructionListParser  
 

Exception Summary
ParseException  
 

Package jelan.elan.parser Description

This package is responsible for parsing the language Elan. It uses recursive descent with, currently, no lookahead.

Adding/Parsing a New Instruction

To parse a new instruction the following steps are followed. We'll use the addition of a statement for an If instruction to the language as an example.

  1. Create a token for the instruction (probably a subclass of token.ReservedToken) with the same prefix as the new instruction, e.g., IfToken.java.

  2. Create a parser for the instruction with the same prefix as the instruction, e.g., IfParser.java. The parsing class (presumably implementing Parser) will return an instance of the parsed Instruction, see the next item.

  3. Create an instruction with prefix name, e.g., If.java in the jelan.elan.instruction package.

  4. Add the instruction name to the file instructions.prop, e.g., add a single line to the file containing the string If.