Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Project: COCKTAIL training
- * Descr: A simple pocket computer (scanner, parser, evaluator)
- * Kind: Parser specification (solution)
- * Author: Prof. Dr. Juergen Vollmer <vollmer@dhbw-karlsruhe.de>
- * $Id: expr.pars.in,v 1.7 2010/04/26 10:53:44 vollmer Exp $
- */
- // Exercises:
- // - Add computation of the "Value" Attribute to all grammar rules.
- // - Test division by 0!
- // - Add grammar and evaluation rules to compute "sin()", "cos()", and "tan()"
- // see man (3) sin
- // Add a grammar and evaluation rule for the constant "pi"
- // - Add more test sources to test your grammar
- SCANNER oberon_scan
- PARSER oberon_pars
- GLOBAL {
- # include <stdio.h>
- # include <math.h>
- }
- PREC LEFT '~'
- LEFT '*' '/' 'DIV' 'MOD' '&'
- LEFT '+' '-' 'OR'
- LEFT '=' '#' '<' '<=' '>' '>=' 'IN' 'IS'
- RULE
- root = all.
- identdef = <
- = tok_identifier '*'
- .
- > . /* identdef */
- qualident = <
- = tok_identifier '.' tok_identifier
- .
- = tok_identifier
- .
- > . /* qualident */
- expression = <
- = '(' expression ')'
- .
- = expression '=' expression
- .
- = expression '#' expression
- .
- = expression '<' expression
- .
- = expression '<=' expression
- .
- = expression '>' expression
- .
- = expression '>=' expression
- .
- = expression 'IN' expression
- .
- = expression 'IS' expression
- .
- = expression '+' expression
- .
- = expression '-' expression
- .
- = expression 'OR' expression
- .
- = expression '*' expression
- .
- = expression '/' expression
- .
- = expression 'DIV' expression
- .
- = expression 'MOD' expression
- .
- = expression '&' expression
- .
- = number
- .
- = char_const
- .
- = string_const
- .
- = 'NIL'
- .
- = '~' expression
- .
- = set
- .
- > . /* expression */
- set = <
- = '{' element_ls '}'
- .
- > . /* set */
- element_ls = < /* <- Das ist eine sperarierte Liste */
- = /* epsilon */
- .
- element_s = <
- = element
- .
- = element_s ',' element
- .
- > . /* element_s */
- >. /* element_ls */
- element = <
- = expression
- .
- = expression '..' expression
- .
- > . /* element */
- number = <
- = int_const
- .
- = real_const
- .
- > . /* number */
- /****************************************/
- all = <
- = int_const
- .
- = real_const
- .
- = char_const
- .
- = string_const
- .
- = identdef
- .
- = qualident
- .
- = expression
- .
- > . /* all */
- /* Tokens */
- int_const: [Value: long] {Value := 0; } .
- real_const: [Value: double] {Value := 0.0; } .
- char_const: [Value: char] {Value := '\0'; } .
- string_const: [Value: tIdent] {Value := NoIdent; } .
- tok_identifier: [Value: tIdent] {Value := NoIdent; } .
- /* non-terminal attributes */
- MODULE attributes
- PROPERTY SYN
- DECLARE
- END attributes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement