在编译器中进行语法和类型检查的最佳方法是什么? [英] What the best way to do syntax and type checking in complier?

查看:195
本文介绍了在编译器中进行语法和类型检查的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建自己的语言并且使用antlr4并且我在线解析...我的问题是:我们可以在线解析中使用两种方法进行语法和类型检查:



第一种方法:



第一次访问ast以检查我是否没有语法错误所以如果我没有任何语法错误错误然后我访问ast进行类型检查...这里我只在没有语法错误时键入检查



第二种方法:



第一次访问ast以检查我是否没有任何语法错误然后我访问ast进行类型检查虽然存在语法错误。 ...在这里我做类型检查,不关心是否存在语法错误...那么在线解析更好的方法是什么?当我们谈论IDE(视觉工作室或日食)使用哪种方法?



我尝试过的方法:



我需要知道最好的方法

I Build my own languge and I use antlr4 and I work on online parse ... my question is : We can do syntax and type checking in online parse in tow methode :

The first methode:

to visit the ast first time to check if I didn't have any syntax errors so If I didn't have any error then I visit ast for do type checking ... here I do type checking only if there are no syntax errors

The second methode :

to visit the ast first time to check if I didn't have any syntax errors then I visit ast for do type checking although there are a syntax errors. ... here I do type checking and don't care if there are syntax error or not ... So what the better methode in online parse ? and when we talke about IDE like (visual studio or eclipse ) which methode use ?

What I have tried:

I need to knew what the best way

推荐答案

非常 ANTLR4的书籍[ ^ ]专门讨论错误处理主题。
The very book of ANTLR4[^] devotes a chapter on the error handling topic.


这篇关于在编译器中进行语法和类型检查的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆