Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Parser {
- private Lexer lex;
- private BufferedReader pbr;
- private Token look;
- public Parser(Lexer l, BufferedReader br) {
- lex = l;
- pbr = br;
- move();
- }
- void move() {
- look = lex.lexical_scan(pbr);
- System.out.println("token = " + look);
- }
- void error(String s) {
- throw new Error("near line " + lex.line + ": " + s);
- }
- void match(int t) {
- if (look.tag == t) {
- if (look.tag != Tag.EOF) move();
- } else error("syntax error");
- }
- public void start() {
- // ... completare ...
- expr();
- match(Tag.EOF);
- // ... completare ...
- }
- private void expr() {
- // ... completare ...
- }
- private void exprp() {
- switch (look.tag) {
- case '+':
- // ... completare ...
- }
- }
- private void term() {
- // ... completare ...
- }
- private void termp() {
- // ... completare ...
- }
- private void fact() {
- // ... completare ...
- }
- public static void main(String[] args) {
- Lexer lex = new Lexer();
- String path = "...path..."; // il percorso del file da leggere
- try {
- BufferedReader br = new BufferedReader(new FileReader(path));
- Parser parser = new Parser(lex, br);
- parser.start();
- System.out.println("Input OK");
- br.close();
- } catch (IOException e) {e.printStackTrace();}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement